import 'package:common_utils/common_utils.dart';
import 'package:fate_blind_box/config/app_style.dart';
import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/widget/meet_appbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'logic.dart';

class SystemChatMessagePage extends GetView<SystemChatMessageLogic> {
  const SystemChatMessagePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const MeetAppBar(
        title: '互动消息',
        centerTitle: true,
      ),
      backgroundColor: '#F2F4F5'.stringToColor,
      body: Obx(() {
        return ListView.builder(
          controller: controller.state.controller,
          padding: EdgeInsets.only(top: 20.w),
          itemBuilder: (context, index) {
            return iteamContext(index);
          },
          itemCount: controller.state.messageList.length,
        );
      }),
    );
  }

  Widget iteamContext(int index) {
    return Obx(() {
      return Container(
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              DateUtil.formatDate(
                  DateTime.fromMillisecondsSinceEpoch(
                      controller.state.messageList[index].serverTime),
                  format: DateFormats.zh_mo_d_h_m),
              style: TextStyle(color: ThemeColor.appColor, fontSize: 11.sp),
            ),
            SizedBox(height: 12.w),
            Align(
              alignment: Alignment.bottomLeft,
              child: SizedBox(
                width: ScreenUtil().screenWidth / 3 * 2,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Image.asset(
                      'images/icon_system.png',
                      width: 34.w,
                      height: 34.w,
                    ),
                    SizedBox(width: 16.w),
                    Expanded(
                        child: Container(
                      padding:
                          EdgeInsets.symmetric(horizontal: 12.w, vertical: 9.w),
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                          topRight: Radius.circular(16.w),
                          bottomLeft: Radius.circular(16.w),
                          bottomRight: Radius.circular(16.w),
                        ),
                      ),
                      child: Text(
                        controller.getMsgTxt(index),
                        style: TextStyle(
                          color: '#333333'.stringToColor,
                        ),
                        maxLines: 20,
                      ),
                    )),
                  ],
                ),
              ),
            ),
            SizedBox(height: 8.w),
          ],
        ),
      );
    });
  }
}
